from Monitor.NetworkMonitor import NetworkDelayMonitor,NetworkMonitor,MonitorType,NetworkBandWidthMonitor
from containernet.node import DockerSta
from OSM_Mininet_wifi.node import OSMDockerStaion,OSMDockerCloud
from containernet.cli import CLI
from containernet.term import makeTerm
from mininet.log import info, setLogLevel,output
from mn_wifi.mobility import Mobility
from mininet.node import Controller
from OSM_Mininet_wifi.net import OSM_Mininet_wifi
from mn_wifi.net import OVSKernelAP

setLogLevel('info')
net = OSM_Mininet_wifi(controller=Controller,autoAssociation=False)


net.addAccessPoint(**{'type': 'bs', 'name': 'bs0', 'location': [28.19917452786327, 112.96940803527833], 'position': [347, 372, 0], 'ssid': 'ssid-bs0', 'ip': '10.0.0.1/8', 'ip6': '2001:0:0:0:0:0:0:1/64', 'mac': '00:00:00:00:00:01', 'range': 500, 'failMode': 'standalone'})
net.addAccessPoint(**{'type': 'bs', 'name': 'bs1', 'location': [28.19535456710196, 112.97487974166872], 'position': [883, -53, 0], 'ssid': 'ssid-bs1', 'ip': '10.0.0.2/8', 'ip6': '2001:0:0:0:0:0:0:2/64', 'mac': '00:00:00:00:00:02', 'range': 500, 'failMode': 'standalone'})
net.addStation(**{'type': 'mp', 'name': 'mp0', 'location': ['28.19460084229876,112.97526168829792', '28.197077123458822,112.96830940253132'], 'position': '921,-137,0', 'ip': '10.0.0.3/8', 'ip6': '2001:0:0:0:0:0:0:3/64', 'mac': '00:00:00:00:00:03', 'range': 500, 'speed': 50, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerStaion)
net.OSM_Mobility_For_ConfigurationData(**{'NodeMobilityConfig': {'speed': 50, 'coord': ['926,-132,0', '1089,-167,0', '1092,-156,0', '929,-120,0', '915,-118,0', '689,-107,0', '621,-103,0', '571,-101,0', '510,-97,0', '490,-96,0', '477,-95,0', '447,-93,0', '432,-92,0', '394,-89,0', '390,123,0', '291,143,0', '238,143,0'], 'distance': 1247.7956486020062}, 'node': 'mp0'})
net.addStation(**{'type': 'mp', 'name': 'mp1', 'location': ['28.20055516193482,112.9682879448592', '28.196510041235452,112.9779224396407'], 'position': '237,525,0', 'ip': '10.0.0.4/8', 'ip6': '2001:0:0:0:0:0:0:4/64', 'mac': '00:00:00:00:00:04', 'range': 500, 'speed': 50, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerStaion)
net.OSM_Mobility_For_ConfigurationData(**{'NodeMobilityConfig': {'speed': 50, 'coord': ['233,538,0', '236,493,0', '328,496,0', '322,481,0', '391,480,0', '390,508,0', '398,524,0', '473,523,0', '476,465,0', '480,375,0', '481,349,0', '481,309,0', '493,309,0', '510,307,0', '602,304,0', '756,297,0', '783,296,0', '935,290,0', '931,128,0', '945,128,0', '1037,113,0', '1116,101,0', '1176,82,0'], 'distance': 1420.1188254603821}, 'node': 'mp1'})
net.addDocker(**{'type': 'ec', 'name': 'ec0', 'location': [28.195716121067544, 112.97635602957601], 'position': [1028, -13, 0], 'ip': '10.0.0.5/8', 'ip6': '2001:0:0:0:0:0:0:5/64', 'mac': '00:00:00:00:00:05', 'range': 500, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerCloud)
net.addDocker(**{'type': 'ec', 'name': 'ec1', 'location': [28.199950293809778, 112.970412254399], 'position': [445, 458, 0], 'ip': '10.0.0.6/8', 'ip6': '2001:0:0:0:0:0:0:6/64', 'mac': '00:00:00:00:00:06', 'range': 500, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerCloud)
net.startController(**{'controller': 'None', 'name': 'c', 'number': 1, 'ip': '127.0.0.1', 'port': 6653, 'protocol': 'tcp', 'app': 'simple_switch'})
net.configureWifiNodes()
net.addLink(**{'type': 'nl', 'node1': 'bs1', 'node2': 'ec0', 'delay': '30ms', 'bw': 10, 'jitter': '0ms', 'loss': 0})
net.addLink(**{'type': 'nl', 'node1': 'bs0', 'node2': 'ec1', 'delay': '5ms', 'bw': 20, 'jitter': '0ms', 'loss': 0})
net.OSM_Mobility_Setting(**{'mobility_start_time': 1, 'reverse': 0, 'ac_method': 'ssf', 'mob_rep': 1, 'mobility_mode': 'quickly'})
net.start()
thread_list = []
t=NetworkDelayMonitor('mp0', 'ec0', net, monitor_type= {'delay'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530220042309763.json',**{'period': 60}).thread_
thread_list.append(t)
t=NetworkDelayMonitor('mp0', 'ec1', net, monitor_type= {'delay'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530220042309763.json',**{'period': 60}).thread_
thread_list.append(t)
t=NetworkBandWidthMonitor('mp1', 'ec0', net, monitor_type= {'band_width'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530220042309763.json',**{'period': 60}).thread_
thread_list.append(t)
t=NetworkBandWidthMonitor('mp1', 'ec1', net, monitor_type= {'band_width'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530220042309763.json',**{'period': 60}).thread_
thread_list.append(t)
for td in thread_list: td.join()
net.OSM_Experiment_Ended(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530220042309763.json')
net.stop()
